package com.xn.app.muying.adpter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.xn.app.muying.R;
import com.xn.app.muying.bean.UnfinishSheetBean;

import java.util.ArrayList;

public class UnfinishSheetAdapter extends BaseAdapter {
    private final LayoutInflater inflater;
    private Context context;
    private ArrayList<UnfinishSheetBean> list = new ArrayList();

    public UnfinishSheetAdapter(Context context) {
        super();
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void getData(ArrayList<UnfinishSheetBean> data) {
        this.list = data;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder holder = null;
        if (view == null) {
            view = inflater.inflate(R.layout.unfinishsheet_item, null);
            holder = new ViewHolder();
            holder.iv = (ImageView) view.findViewById(R.id.unfinishsheet_item_iv);
            holder.title = (TextView) view.findViewById(R.id.unfinishsheet_item_title);
            holder.tv = (TextView) view.findViewById(R.id.unfinishsheet_item_tv);
            holder.time = (TextView) view.findViewById(R.id.unfinishsheet_item_time);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        switch (list.get(i).getProcessStatus()) {
            case "0":
                holder.iv.setImageResource(R.mipmap.reading);
                holder.title.setText("解读中");
                holder.tv.setText("正在为您解读，请稍后");
                String[] strs = list.get(i).getReporterDate().split("T");
                String[] strs2 = strs[1].split(":");
                holder.time.setText("" + strs[0] + " " + strs2[0] + ":" + strs2[1]);
                break;
            case "1":
                holder.iv.setImageResource(R.mipmap.finish);
                holder.title.setText("已解读");
                holder.tv.setText("需确认异常指标");
                String[] strs_01 = list.get(i).getReporterDate().split("T");
                String[] strs2_01 = strs_01[1].split(":");
                holder.time.setText("" + strs_01[0] + " " + strs2_01[0] + ":" + strs2_01[1]);
                break;
            case "2":
                holder.iv.setImageResource(R.mipmap.reading);
                holder.title.setText("识别出错");
                holder.tv.setText("您上传的图片暂时无法识别");
                String[] strs_02 = list.get(i).getReporterDate().split("T");
                String[] strs2_02 = strs_02[1].split(":");
                holder.time.setText("" + strs_02[0] + " " + strs2_02[0] + ":" + strs2_02[1]);
                break;
        }
        return view;
    }

    class ViewHolder {
        ImageView iv;
        TextView tv, title, time;
    }
}
